package cz.tomasdvorak.cars.dao;

import cz.tomasdvorak.cars.dto.User;
import cz.tomasdvorak.cars.exceptions.RegistrationFailedException;

import java.util.List;

public interface UsersDao {
    /**
     * @return list of all users
     */
    List<User> getAllUSers();

    /**
     * Register new user to system
     * @param name username
     * @param password password, plaintext, will be hashed
     * @throws RegistrationFailedException in case anything went wrong
     */
    void registerNewUser(String name, String password) throws RegistrationFailedException;

    /**
     * Tests, if user with given username exists and password is the same as provided
     * @param username given username
     * @param password given password
     * @return user or {@code null} if not authenticated
     */
    User authenticate(String username, String password);

    /**
     * Change given user password
     * @param user user for password changing
     * @param oldPassword old pass, to be sure is allowed to change it
     * @param newPassword new pass to set
     * @throws IllegalAccessException if user given illegal old pass or tries to change
     *  another user password
     */
    void changePassword(User user, String oldPassword, String newPassword) throws
            IllegalAccessException;

    /**
     * @param id user id
     * @return user with given id
     */
    User getUserById(int id);
}
